package com.apache.bid.controller.admin;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.apache.api.vo.ParamsVo;
import com.apache.bid.controller.BaseSupperAction;
import com.apache.bid.entity.BidPrintParam;
import com.apache.bid.manager.BidPrintParamManager;
import com.apache.bid.manager.UnityBaseManager;
import com.apache.cache.util.Validator;

@Controller
@RequestMapping("/admin/para")
public class BidPrintParamAction extends BaseSupperAction<BidPrintParam> {

	@Autowired
	private BidPrintParamManager bidPrintParamManager;

	/**
	 *根据sessionId查询单个对象，返回JSON数据
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = { "/byObjId/{objId}/{objType}" }, method = { RequestMethod.GET })
	@ResponseBody
	protected Object getParaByObjId(@PathVariable String objId, @PathVariable String objType, HttpServletRequest request) {
		Map<String, Object> mapData = new HashMap<String, Object>();

		if (Validator.isNull(objId) || Validator.isNull(objType)) {
			mapData.put("flag", "F");
			mapData.put("msg", "缺少必要的参数！");
			return mapData;
		}

		ParamsVo<BidPrintParam> paraVo = new ParamsVo<BidPrintParam>();
		BidPrintParam para = new BidPrintParam();
		try {
			if ("sessionId".equals(objType)) {
				para.setSessionId(objId);
			} else if ("itemId".equals(objType)) {
				para.setItemId(objId);
			} else {
				mapData.put("flag", "F");
				mapData.put("msg", "参数错误！");
				return mapData;
			}

			paraVo.setObj(para);
			paraVo.setMethodKey("singleParaByAttr");
			BidPrintParam bidParam = (BidPrintParam) bidPrintParamManager.execute(paraVo);
			if (bidParam == null) {
				mapData.put("flag", "F");
				mapData.put("msg", "查询失败！");
			} else {
				mapData.put("flag", "T");
				mapData.put("msg", "查询成功！");
				mapData.put("entity", bidParam);
			}
		} catch (Exception e) {
			mapData.put("flag", "F");
			mapData.put("msg", "查询错误！");
			this.logger.error("根据" + objType + "查询单个para对象错误！" + e.getMessage());
		}

		return mapData;
	}

	@Override
	protected UnityBaseManager<BidPrintParam> getBaseManager() {
		return this.bidPrintParamManager;
	}

	@Override
	protected String getCommBoxValue(BidPrintParam item, String type) {
		return null;
	}

}
